//
//  CYMBShow.swift
//  Exchange
//
//  Created by 孟祥群 on 2018/6/6.
//  Copyright © 2018年 common. All rights reserved.
//

import UIKit
import Foundation
import MBProgressHUD
class CYMBShow: NSObject {
    
    /// 创建MB指示器
    ///
    /// - Parameters:
    ///   - message: 信息
    ///   - view: 所在的view
   public class func openIndicator(message:String?, view:UIView?) {

        MBProgressHUD.showMessage(message: message, toView: view != nil ? view : CYMBShow.currentView())
    }
    
     ///关闭指示器
   public class func colseIndicator(view:UIView? = nil) {
    MBProgressHUD.hideHUDForView(view: view != nil ? view : CYMBShow.currentView())
    }
    
    
    /// 提示信息
    ///
    /// - Parameter message: 提示信息的文本
   public class func showMessage(_ message:String) {
        UIApplication.shared.keyWindow?.displayMessage(message: message)
    }
    
    class func currentController() -> UIViewController? {
        if UIApplication.shared.keyWindow == nil {
            return nil
        }
        let window = UIApplication.shared.keyWindow!
        if let tabVc = window.rootViewController as? BaseTabBarViewController,let selectNavi =
            tabVc.selectedViewController as? NavigationController {
            if let vc = selectNavi.rui_viewControllers.last {
                return vc
            }
        }
        return nil
    }
    
    
    class func currentView() -> UIView {
        let window = UIApplication.shared.keyWindow!
        if let tabVc = window.rootViewController as? BaseTabBarViewController,let selectNavi = tabVc.selectedViewController as? NavigationController {
            if let vc = selectNavi.rui_viewControllers.last {
                if selectNavi.rui_viewControllers.count == 1 {
                    return window
                }
                return vc.view
            }
        }
        return window
    }
    
    
}
